package com.linshuo.employee.controller;

import com.linshuo.employee.entity.FamilyMember;
import com.linshuo.employee.service.FamilyMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/family-members")
public class FamilyMemberController {
    @Autowired
    private FamilyMemberService familyMemberService;

    @PostMapping
    public FamilyMember createFamilyMember(@RequestBody FamilyMember familyMember) {
        return familyMemberService.saveFamilyMember(familyMember);
    }

    @PutMapping("/{id}")
    public FamilyMember updateFamilyMember(@PathVariable Long id, @RequestBody FamilyMember familyMember) {
        familyMember.setId(id);
        return familyMemberService.updateFamilyMember(familyMember);
    }

    @DeleteMapping("/{id}")
    public void deleteFamilyMember(@PathVariable Long id) {
        familyMemberService.deleteFamilyMember(id);
    }

    @GetMapping("/{id}")
    public FamilyMember getFamilyMemberById(@PathVariable Long id) {
        return familyMemberService.getFamilyMemberById(id);
    }

    @GetMapping
    public List<FamilyMember> getAllFamilyMembers() {
        return familyMemberService.getAllFamilyMembers();
    }
} 